table.insert(itemActions,
	function(item, action)
		-- MAGIC grandcharms
		local baalgcs = false -- true will keep all Ilvl 94+ (Baal + Nihl) gcs
		-- see: dir .. "readme.txt" for information regarding these variables
		local priority = 7
		local identify = true
		local dump = true

		if not (item.quality == ItemQuality.Magic and item.baseItem.code == "cm3") then
			return false
		elseif action == aPICK and (not item.flags.Identified or isGoodGrandCharm(item, baalgcs)) then
			return priority
		elseif action == aIDENT then
			return identify
		elseif action == aSELL and item.flags.Identified and not isGoodGrandCharm(item, baalgcs) then
			return true
		elseif action == aDUMP and item.flags.Identified and not isGoodGrandCharm(item, baalgcs) then
			return dump
		end

		return false
	end
)

function isGoodGrandCharm(item, baalgcs)
	if baalgcs == true and item.level >= 94 then
		return true
	end
	-- note: mp, ar, maxdam, and hp are all assigned values
	-- so you can add custom gcs in the return
	-- do not try to compare other variables (bools) with numbers
	-- feel free to change the lower prefix/suffix bounds
	local prefix = false
	local mp, ar, maxdam, gf = 0, 0, 0, 0
	local suffix = false
	local hp, fhr, frw = 0, false, false
	local affix = false

	if hasRes(item, 7, 4) or hasRes(item, 15, 1) then -- 7-9 allres or 15-24 singleres->prefix
		prefix = true
	end
	
	if hasRes(item, 10, 4) or hasRes(item, 25, 1) then -- 10-12 allres or 25-30 singleres ->KEEP
        return true
	end

	for i = 0, item.mods:size() - 1 do
		if item.mods[i].Stat.Type == StatType.MaxMana then
			if item.mods[i].Value >= 30 then -- 40+mp->prefix
				prefix = true
			end
			mp = item.mods[i].Value
		elseif item.mods[i].Stat.Type == StatType.ToHit then
			if item.mods[i].Value >= 60 then -- 100+ar->prefix
				prefix = true
			end
			ar = item.mods[i].Value
		elseif item.mods[i].Stat.Type == StatType.MaxDamage then
			if item.mods[i].Value >= 5 then -- 7+maxdam->prefix
				prefix = true
			end
			maxdam = item.mods[i].Value
		elseif item.mods[i].Stat.Type == StatType.GoldFind then
			if item.mods[i].Value >= 35 then -- 39+gf->affix
				suffix = true
			end
			gf = item.mods[i].Value
		elseif item.mods[i].Stat.Type == StatType.MaxLife then
			if item.mods[i].Value >= 30 then -- 40+hp->suffix
				suffix = true
			end
			hp = item.mods[i].Value
		elseif item.mods[i].Stat.Type == StatType.FasterHitRecovery then
			fhr = true -- fhr->suffix
			suffix = true
		elseif item.mods[i].Stat.Type == StatType.FasterMoveVelocity then
			frw = true -- frw->suffix
			suffix = true
		elseif item.mods[i].Stat.Type == StatType.SkillTabBonus then
			affix = true -- skiller->affix
		end
	end

	return (
			(ar >= 40 and maxdam >= 6) or -- example of a custom rule
            prefix or
			suffix or
			affix
			)
end
